package bairui.international.console.web.controller.advance.category.properties.item;

import java.util.List;
import java.util.stream.Collectors;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.lianjing.sh.validate.spring.exception.ValidateObjectException;

import bairui.international.model.domain.jpa.TB_ProductCategoryProperty;
import bairui.international.model.domain.jpa.TB_ProductPropertyItem;
import bairui.international.model.domain.jpa.id.ID_ProductCategoryProperty;
import bairui.international.service.Service_ProductCategoryPropertyItem;

/**
 *
 * 属性项添加
 *
 * @generated
 * 
 * @see STest_C_Advance_Category_PropertiesItemAdd_Submits 测试
 *
 */
@Controller
public class C_Advance_Category_PropertiesItemAdd_Submits
 extends SC_Advance_Category_PropertiesItemAdd_Submits 
{
	
	@Autowired private Service_ProductCategoryPropertyItem service_ProductCategoryPropertyItem;
	
	/**
	 * 提交
	 */
	@Action(Submits.class)
	@PostMapping(Submits.RequestMappingValue)
	public @FomatOutput @ResponseBody Object submits(
		@Valid Submits.Input input, 
		@PathVariable(name=Submits.PathVariableName.CategoryId) long categoryId, 
		@PathVariable(name=Submits.PathVariableName.PropertyId) ID_ProductCategoryProperty propertyId
	) throws Exception {
		List<Long> ids = input.getId();
		if(ids.isEmpty()){
			throw new ValidateObjectException("object", "", "选择不能为空");
		}
		//
		service_ProductCategoryPropertyItem.create(
				new TB_ProductCategoryProperty(propertyId),
				ids
					.stream()
					.map(it->new TB_ProductPropertyItem(it))
					.collect(Collectors.toList())
			);
		//
		return null;
	}
	

}
